package com.info.zhiduoduo.repository.mapper.foreign;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.foreign.ForeignProjectDraftListDto;
import com.info.zhiduoduo.repository.entity.foreign.ForeignProjectDraft;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 对外项目草稿表 Mapper 接口
 * </p>
 *
 * @author cuichenglong
 * @since 2020-10-09
 */
public interface ForeignProjectDraftMapper extends BaseMapper<ForeignProjectDraft> {

    @Select(" SELECT fpd.createtime AS orderTime, cp.createtime, cp.project_no, fpd.batch_number, " +
            " fpd.order_number, fpd.tax_money, fpd.project_service_charge, fpd.request_money, c.compname, " +
            " fpd.crowdsource_number, fpd.idno, ca.realname FROM zdd_foreign_project_draft fpd " +
            " LEFT JOIN zdd_crowdsource_project cp ON cp.projectid = fpd.project_id " +
            " LEFT JOIN zdd_crowdsource_account ca ON ca.crowdsourceid = fpd.crowdsourceid " +
            " LEFT JOIN zdd_company c ON c.compid = fpd.company_id WHERE fpd.flag = 1 " +
            " AND fpd.createtime BETWEEN #{startOrderTime} AND #{endOrderTime} " +
            " AND cp.createtime BETWEEN #{startCreateTime} AND #{endCreateTime} " +
            " AND IF(ISNULL(#{number}) OR #{number} = '', 1=1, cp.project_no = #{number} " +
            "        OR fpd.batch_number = #{number} OR fpd.order_number = #{number} OR fpd.idno = #{number}) " +
            " AND IF(ISNULL(#{name}) OR #{name} = '', 1=1, CONCAT( c.compname, ca.realname ) like '%${name}%')")
    List<ForeignProjectDraftListDto> queryForeignProjectDraftByCondition(Date startOrderTime, Date endOrderTime,
                                                                         Date startCreateTime, Date endCreateTime,
                                                                         String number, String name);

}
